package com.tucc.hello.leetcode.no1_400.no1_200.no1_20.no1_10.no7;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();

    }

    public int reverse(int x) {
        if(x == 0) {
            return x;
        }
        boolean positive = x > 0;
        int n = positive ? x : -x;
        String str = new StringBuilder(n + "").reverse().toString();
        int rev = 0;
        try{
            rev = Integer.valueOf(str);
        }catch (Exception e){
        }
        if(rev > 0){
            return positive ? rev : -1 * rev;
        }
        return 0;
    }

}
